package com.zc.operator.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zc.operator.domain.ChargeMchInfo;
import com.zc.operator.service.IChargeMchInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商户Controller
 *
 * @author ruoyi
 * @date 2024-05-16
 */
@RestController
@RequestMapping("/operator/mch")
public class ChargeMchInfoController extends BaseController {
    @Autowired
    private IChargeMchInfoService chargeMchInfoService;

    /**
     * 查询商户列表
     */
    @PreAuthorize("@ss.hasPermi('operator:mch:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChargeMchInfo chargeMchInfo) {
        startPage();
        List<ChargeMchInfo> list = chargeMchInfoService.selectChargeMchInfoList(chargeMchInfo);
        return getDataTable(list);
    }

    @GetMapping("/allList")
    public AjaxResult allList() {
        List<ChargeMchInfo> list = chargeMchInfoService.selectChargeMchInfoList(null);
        return AjaxResult.success(list);
    }


    /**
     * 导出商户列表
     */
    @PreAuthorize("@ss.hasPermi('operator:mch:export')")
    @Log(title = "商户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChargeMchInfo chargeMchInfo) {
        List<ChargeMchInfo> list = chargeMchInfoService.selectChargeMchInfoList(chargeMchInfo);
        ExcelUtil<ChargeMchInfo> util = new ExcelUtil<>(ChargeMchInfo.class);
        util.exportExcel(response, list, "商户数据");
    }

    /**
     * 获取商户详细信息
     */
    @PreAuthorize("@ss.hasPermi('operator:mch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(chargeMchInfoService.selectChargeMchInfoById(id));
    }

    /**
     * 新增商户
     */
    @PreAuthorize("@ss.hasPermi('operator:mch:add')")
    @Log(title = "商户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChargeMchInfo chargeMchInfo) {
        return toAjax(chargeMchInfoService.insertChargeMchInfo(chargeMchInfo));
    }

    /**
     * 修改商户
     */
    @PreAuthorize("@ss.hasPermi('operator:mch:edit')")
    @Log(title = "商户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChargeMchInfo chargeMchInfo) {
        return toAjax(chargeMchInfoService.updateChargeMchInfo(chargeMchInfo));
    }

    /**
     * 删除商户
     */
    @PreAuthorize("@ss.hasPermi('operator:mch:remove')")
    @Log(title = "商户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(chargeMchInfoService.deleteChargeMchInfoByIds(ids));
    }
}
